/*
 * @lc app=leetcode.cn id=1093 lang=cpp
 *
 * [1093] 大样本统计
 */

// @lc code=start
class Solution {
public:
    vector<double> sampleStats(vector<int>& count) {
        vector<double>ct;
        int len = count.size();
        double max_n = static_cast<double>(count[0]);
        double min_n = static_cast<double>(count[0]);
        double nums= 0;
        double sum = 0;
        double zws;
        double zs;
        vector<int>v;
        vector<int>table;
        for(int i = 0; i < len;i++){
            if(count[i] == 0) continue;
            nums ++;
            v.push_back(count[i]);
            sum +=count[i];
            max_n = (max_n>count[i]? max_n:count[i]);
            min_n = (min_n<count[i]? min_n:count[i]);
        }
        int len_of_v = v.size();
        if(len_of_v % 2 == 0){
            double s1=static_cast<double>(v[len_of_v/2-1]);
            double s2=static_cast<double>(v[len_of_v/2]) ;
            zws = (s1+s2)/2;
        }else {
            zws = static_cast<double> (v[len_of_v /2]);
        }
        for(int i = 0; i< len_of_v;i++){
            int cc = 0;
            for(int j = 0;j<len_of_v;j++){
                if(v[i]== v[j])
                cc++;
            }
            table.push_back(cc);
        }
        int tmp=1;
        for(int i = 0; i< table.size();i++){
            tmp = (tmp > table[i] ? tmp : table[i]);
        }
        for(int i = 0;i< table.size();i++){
            if(tmp == table[i]){
                zs = static_cast<double>(v[i]);
                break;
            }
        }


        double average_ = sum / nums;
        ct.push_back(min_n);
        ct.push_back(max_n);
        ct.push_back(average_);
        ct.push_back(zws);
        ct.push_back(zs);

        return ct;
    }
};
// @lc code=end

